const path = require("path");

/**
 * Common
 */
function shake(obj) {
  return Object.keys(obj).reduce(
    (res, key) => (Boolean(obj[key]) ? { ...res, [key]: obj[key] } : res),
    {}
  );
}
function createRetry(fn, maxRetryCount) {
  let retryCount = 0;

  async function withRetry(...args) {
    try {
      return await fn.apply(this, args);
    } catch (error) {
      if (retryCount++ < maxRetryCount) {
        return withRetry(...args);
      }
    }
  }

  return withRetry;
}
module.exports.shake = shake;
module.exports.createRetry = createRetry;

/**
 * Time
 */
function padZero(value) {
  return `0${value}`.slice(-2);
}
function now() {
  const date = new Date();
  const year = date.getFullYear();
  const month = padZero(date.getMonth() + 1);
  const day = padZero(date.getDate());
  const hour = padZero(date.getHours());
  const min = padZero(date.getMinutes());
  const second = padZero(date.getSeconds());
  
  return `${year}-${month}-${day} ${hour}:${min}:${second}`;
}

module.exports.padZero = padZero;
module.exports.now = now;
